<template>
  <div class="newsinfo-container">
    <!-- 标题 -->
    <h3 class="title">{{newsDetial.title}}</h3>
    <!-- 子标题 -->
    <p class="subtitle">
      <span>发表时间：{{newsDetial.add_time | dataFormat}}</span>
      <span>点击：{{newsDetial.click}}次</span>
    </p>

    <hr>
    <!-- 内容区域 -->
    <div class="content" v-html="newsDetial.content">
      <!-- {{newsDetial.content}} -->
    </div>
    <!-- 评论区域 -->
    <comment-box :id='this.id'></comment-box>
  </div>
</template>

<script>
// 导入 评论子组件
import comment from "../subcomponents/comment.vue";

import { Toast } from "mint-ui";

export default {
  data() {
    return {
      id: this.$route.params.id, // 将URL 地址中传递过来的id值，挂载到 data上 方便调用
      newsDetial: {}
    };
  },
  methods: {
    getDetial() {
      this.$http.get("api/getnew/" + this.id).then(res => {
        if (res.body.status === 0) {
          this.newsDetial = res.body.message[0];
        } else {
          Toast("获取数据失败");
        }
      });
    }
  },
  created() {
    this.getDetial();
  },
  components: {
    // 用来注册子组件的节点
    "comment-box": comment
  }
};
</script>

<style lang='less'>
.newsinfo-container {
  padding: 0 5px;
  .title {
    font-size: 16px;
    margin: 15px 0;
    color: red;
    text-align: center;
  }
  .subtitle {
    font-size: 12px;
    color: #226aff;
    display: flex;
    justify-content: space-between;
  }
  .content {
    img {
      height: 100%;
      width: 100%;
    }
  }
}
</style>
